package com.suieqian.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.suieqian.config.dblimit.DbRecordLimitInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *  MybatisPlus 配置
 * @author win10
 */
@Configuration
@MapperScan("com.suieqian.dao")
public class MybatisPlusConfig {

        @Bean
        public MybatisPlusInterceptor mybatisPlusInterceptor() {
            MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
            // 分页插件
            interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
            // 防止全表更新与删除插件
            interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
            // 自定义插件每次查询最大条数
            DbRecordLimitInterceptor limitInterceptor = new DbRecordLimitInterceptor();
            limitInterceptor.setLimitSize(5000);
            interceptor.addInnerInterceptor(limitInterceptor);
            return interceptor;
        }


}
